package org.lql.chaos.rocketmq.service.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.lql.chaos.rocketmq.callback.OrderSendCallback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: liangqinglong
 * @date: 2025-08-15 17:22
 * @description: 普通消息生产者
 **/
@Slf4j
@Service
public class NormalProducer {

	@Autowired
	private RocketMQTemplate rocketMQTemplate;

	public void sendOneWay(String topic, String tag, String msg) {
		log.info("发送普通单向消息：{}", msg);
		rocketMQTemplate.sendOneWay(topic + ":" + tag, msg);
	}

	public void sendSync(String topic, String tag, String msg) {
		log.info("发送普通同步消息：{}", msg);
		SendResult sendResult = rocketMQTemplate.syncSend(topic + ":" + tag, msg);
		log.info("普通同步消息发送结果：{}", sendResult);
	}

	public void sendAsync(String topic, String tag, String msg) {
		log.info("发送普通异步消息：{}", msg);
		// 使用监控回调类替换匿名内部类
		rocketMQTemplate.asyncSend(topic + ":" + tag, msg, 
			new OrderSendCallback());
	}

	public void sendAsyncWithMonitor(String topic, String tag, String msg) {
		log.info("发送普通异步消息 带监控功能的消息发送回调类：{}", msg);
		// 使用监控回调类替换匿名内部类
		rocketMQTemplate.asyncSend(topic + ":" + tag, msg,
			new MonitoredSendCallback("普通业务", topic));
	}
}